<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

abstract class Request extends FormRequest
{
    #https://laracasts.com/discuss/channels/general-discussion/laravel-5-modify-input-before-validation
    #https://github.com/laravel/framework/commit/924a7fcf21bbba4f4efc8e367f456cea5e4d25c1
    /**
     * The sanitized input.
     *
     * @var array
     */
    protected $sanitized;

    public function validator($factory)
    {
        return $factory->make(
            $this->sanitizeInput(), 
            $this->container->call([$this, 'rules']), 
            $this->messages()
        );
    }

    /**
     * Sanitize the input.
     *
     * @return array
     */
    protected function sanitizeInput()
    {
        if (method_exists($this, 'sanitize'))
        {
            return $this->sanitized = $this->container->call([$this, 'sanitize']);
        }
        
        return $this->all();
    }
}
